﻿
@{
    ViewBag.Title = "我的收藏";
    Layout = "~/Views/Shared/_UserHomeLayout.cshtml";
}
@model Nutshell.Blog.Model.Favorites

@section style{

    <link href="~/Content/mWindow/mWindow.css" rel="stylesheet" />
}

<div class="tabs">
    <ul class="tabs-nav">
        <li class="active"><a href="javascript:void(0);" onclick="loadFavorites();">收藏列表</a></li>
        <li><a href="javascript:void(0);">我的标签</a></li>
    </ul>
    <div class="tabs-content">
        <div class="tab-panel active">
            <table id="favorites" class="mDataTable" cellspacing="0" style="width:100%">
                <thead>
                    <tr>
                        <th class="hidden">Id</th>
                        <th>文章标题</th>
                        <th class="center" width="100px">操作</th>
                    </tr>
                </thead>
            </table>
        </div>
        <div class="tab-panel">
            我的标签
        </div>
    </div>
</div>
<div id="editwindow" style="display:none;">
    <h1>编辑收藏</h1>
    <form>
        <input type="text" name="" />
        <input type="text" name="" />
        <input type="button" value="完成" />
    </form>
</div>
@section script{
    <script src="~/Content/scripts/common.js"></script>
    <script src="~/Content/mWindow/mWindow.js"></script>
    <script>
        $(function () {
            loadFavorites();
        });
        function loadFavorites() {
            $('#favorites').mDataTable({
                ajax: {
                    url: "/user/getfavorites",
                    type: 'POST'
                },
                columns: [
                    { data: 'Article_Id', hidden: true },
                    {
                        data: 'Title', render: function (data, row) {
                            var date = row["Collection_Time"];
                            date.replace(/Date\([\d+]+\)/, function (a) { eval('d = new ' + a) });
                            return '<a target="_blank" href="/' + row["author"] + '/p/' + row["Article_Id"] + '.html">' + data + '</a><span class="time">(' + d.format("yyyy-MM-dd hh:mm:ss") + ')</span>';
                        }
                    },
                    {
                        data: 'Article_Id', class: 'center', render: function (data, row) {
                            return '<a href="#" onclick=\'edit_favorite(' + data + ');return false;\'">编辑</a> | <a href="#" onclick="del_favorite(' + data + ')" name="del">删除</a>';
                        }
                    }
                ]
            });
        }

        function edit_favorite(id) {
            layer.open({
                type: 2,
                title: '编辑收藏',
                area: ['450px', '400px'],
                fixed: false, //不固定
                content: '/favorite/edit?articleId=' + id
            });
        }

        function del_favorite(id) {
            layer.confirm('确定删除该收藏吗？', {
                title: '删除确认',
                btn: ['确定', '取消'] //按钮
            }, function () {
                $.post('/user/DeleteFavorite', { articleid: id }, function (data) {
                    if (data.code == 0) {
                        layer.msg('删除成功', { icon: 1 });
                        loadFavorites();
                    } else {
                        layer.msg('删除失败，请重试！', { icon: 2 });
                    }
                });

            }, function () {

            });
        }
    </script>
}